<link href="{$base_dir}css/main_menu.css" rel="stylesheet" type="text/css">
<script src="{$base_dir}js/dimensions.js" type="text/javascript"></script>
<script src='{$base_dir}js/AJAX_Ticket.js' type="text/javascript" ></script>
<script src='{$base_dir}js/jquery.contextmenu.r2.packed.js' type="text/javascript" ></script>
<script type="text/javascript">
{if isset($newTicket)}	
	var ticketId = {$newTicket.ticket_id};	
	{literal}										
	$(document).ready(function() {
		$('#add_ticket_button').hide();
		viewOpenTicket(ticketId);
	});
	{/literal}
{else}
	{if $userRole == 'front_office'}
		addTicket();
	{/if}
{/if}
{if isset($errPatientNotFound)}
	{literal}			
	$(document).ready(function() {
		$('#element_ticket').hide();	
	});		
	{/literal}
{/if}
{literal}										
$(document).ready(function() {
	$('#ticketList').change(function(){
		$("#ticketList option:selected").each(function () {
			var val = $(this).val();
			if (val != -1 && val != 0) {
				var prefix = val.charAt(0);
				var suffix = val.substring(1);
				if (prefix == 'N') {
					viewOpenTicket(suffix);
				} else {
					viewClosedTicket(suffix);
				}
			} else if (val == 0) {
				$('#view_closed_ticket').hide();				
				$('#add_ticket_button').show();
				$('#intro_sentence').show();
			}
		});
	});
});
{/literal}
</script>
<div id='ticketSelector' style='text-align: right; margin-bottom: 5px;'>
	<select id='ticketList' style='width: 200px'>
		<optgroup id='newTicketGroup' label="{translate}Open ticket{/translate}">
		{if isset($newTicket)}
			<option id='newTicket' value="N{$newTicket.ticket_id}" selected='selected'>{$newTicket.name}</option>						
		{else}
			<option id='noTicket' value='0' selected='selected'>{translate}Not yet{/translate}!</option>
		{/if}
		</optgroup>
		<optgroup id='oldTicketGroup' label="{translate}Closed ticket{/translate}">
		{if isset($ticketTree)}
			{foreach from=$ticketTree item=aTicket}
			<option value="O{$aTicket.ticket_id}">{$aTicket.name}</option>						
			{/foreach}
		{else}
			<option value='-1'>{translate}Not yet{/translate}!</option>
		{/if}
		</optgroup>
	</select>
</div>	
<div id="element_ticket">
	<div id="intro_sentence" style='padding: 10px 10px 10px 20px'>
	<input type="hidden" id="patient_id" value="{$patientId}">
	{if $userRole == 'front_office'}			
		<a class='contentLink' href="#" id="add_ticket_button">
			<img src="{$base_uri}/images/arrow_circle.png" border='0' align='top'/>
			<span>{translate}Create a new service ticket{/translate}...</span>
		</a>
	{else}
		<span style='font-weight: bold; color: red'>
			{translate}Don't have a service ticket yet. Patient must go to receptionist for making new service ticket before go to examine{/translate}.
		</span>
	{/if}														
	</div>					
	<div id="add_ticket" style="display:none;">				
		{include file="ticket/element_add.html"}				
	</div>	
	<div id="view_closed_ticket" style="display:none;">
		{include file="ticket/element_view_closed_ticket.html"}
	</div>
</div>